package jmeshless;


import FEMShapeFunction1D.FEMShapeFunction1D1;
import jmeshless.NewOkCancelDialog;
import FEMSolver1D.MainMatrixGenerator1;
import Integration.GaussQuadrature;
import Integration.IFunction1D;
import MF1DSolver.MF1DSolver;
import MeshlessShapeFunctions.IKernelFunction;
import MeshlessShapeFunctions.JCubicSpline;
import MeshlessShapeFunctions.JExponential;
import MeshlessShapeFunctions.JGaussian;
import MeshlessShapeFunctions.JMeshlessInterpolationFunction1D;
import MeshlessShapeFunctions.JStKernel;
import MeshlessShapeFunctions.Particle;
import java.awt.Dimension;
import java.util.ArrayList;
import javax.swing.JFrame;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;

import syntaxanalyser.PostfiksX;

import javax.swing.GroupLayout.Alignment;
import javax.swing.GroupLayout;
import javax.swing.LayoutStyle.ComponentPlacement;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ParamsPanel.java
 *
 * Created on 15 лют 2010, 20:38:45
 */

/**
 *
 * @author mark_o
 */
public class ParamsPanel extends javax.swing.JPanel {

    /** Creates new form ParamsPanel */
    public ParamsPanel() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTextFieldP = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jTextFieldQ = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jTextFieldW = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldF = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jComboBoxA = new javax.swing.JComboBox();
        jTextFieldBLeft = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jComboBoxB = new javax.swing.JComboBox();
        jTextFieldBRight = new javax.swing.JTextField();
        jPanel5 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jTextFieldA = new javax.swing.JTextField();
        jTextFieldB = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jPanel6 = new javax.swing.JPanel();
        jComboBoxType = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        jTextFieldN = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jComboBox4 = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        jTextFieldPow = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jTextFieldRho = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jTextFieldNorma = new javax.swing.JTextField();

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Параметри"));

        jLabel1.setText("p");

        jTextFieldP.setText("1");

        jLabel2.setText("q");

        jTextFieldQ.setText("0");
        jTextFieldQ.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldQActionPerformed(evt);
            }
        });

        jLabel3.setText("w");

        jTextFieldW.setText("100");
        jTextFieldW.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldWActionPerformed(evt);
            }
        });

        jLabel4.setText("f");

        jTextFieldF.setText("100");

        javax.swing.GroupLayout gl_jPanel1 = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(gl_jPanel1);
        gl_jPanel1.setHorizontalGroup(
            gl_jPanel1.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gl_jPanel1.createSequentialGroup()
                .addGroup(gl_jPanel1.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(gl_jPanel1.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(jTextFieldP, javax.swing.GroupLayout.DEFAULT_SIZE, 266, Short.MAX_VALUE))
                    .addGroup(gl_jPanel1.createSequentialGroup()
                        .addGroup(gl_jPanel1.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addGap(18, 18, 18)
                        .addGroup(gl_jPanel1.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextFieldW, javax.swing.GroupLayout.DEFAULT_SIZE, 264, Short.MAX_VALUE)
                            .addComponent(jTextFieldQ, javax.swing.GroupLayout.DEFAULT_SIZE, 264, Short.MAX_VALUE)
                            .addComponent(jTextFieldF, javax.swing.GroupLayout.DEFAULT_SIZE, 264, Short.MAX_VALUE))))
                .addContainerGap())
        );
        gl_jPanel1.setVerticalGroup(
            gl_jPanel1.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gl_jPanel1.createSequentialGroup()
                .addGroup(gl_jPanel1.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextFieldP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(gl_jPanel1.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jTextFieldQ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(gl_jPanel1.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextFieldW, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(gl_jPanel1.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTextFieldF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Граничні умови"));

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Ліва"));

        jComboBoxA.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Діріхле", "Неймана" }));

        jTextFieldBLeft.setText("0");

        javax.swing.GroupLayout gl_jPanel3 = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(gl_jPanel3);
        gl_jPanel3.setHorizontalGroup(
            gl_jPanel3.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jComboBoxA, 0, 116, Short.MAX_VALUE)
            .addComponent(jTextFieldBLeft, javax.swing.GroupLayout.DEFAULT_SIZE, 116, Short.MAX_VALUE)
        );
        gl_jPanel3.setVerticalGroup(
            gl_jPanel3.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gl_jPanel3.createSequentialGroup()
                .addComponent(jComboBoxA, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldBLeft, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Права"));

        jComboBoxB.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Діріхле", "Неймана" }));

        jTextFieldBRight.setText("0");

        javax.swing.GroupLayout gl_jPanel4 = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(gl_jPanel4);
        gl_jPanel4.setHorizontalGroup(
            gl_jPanel4.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jComboBoxB, 0, 140, Short.MAX_VALUE)
            .addComponent(jTextFieldBRight, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)
        );
        gl_jPanel4.setVerticalGroup(
            gl_jPanel4.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gl_jPanel4.createSequentialGroup()
                .addComponent(jComboBoxB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldBRight, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout gl_jPanel2 = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(gl_jPanel2);
        gl_jPanel2.setHorizontalGroup(
            gl_jPanel2.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gl_jPanel2.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        gl_jPanel2.setVerticalGroup(
            gl_jPanel2.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gl_jPanel2.createSequentialGroup()
                .addGroup(gl_jPanel2.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel3, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Проміжок"));

        jLabel5.setText("a");

        jTextFieldA.setText("0");

        jTextFieldB.setText("1");

        jLabel6.setText("b");

        javax.swing.GroupLayout gl_jPanel5 = new javax.swing.GroupLayout(jPanel5);
        gl_jPanel5.setHorizontalGroup(
        	gl_jPanel5.createParallelGroup(Alignment.LEADING)
        		.addGroup(gl_jPanel5.createSequentialGroup()
        			.addGroup(gl_jPanel5.createParallelGroup(Alignment.LEADING)
        				.addComponent(jTextFieldA, GroupLayout.PREFERRED_SIZE, 124, GroupLayout.PREFERRED_SIZE)
        				.addComponent(jLabel5))
        			.addPreferredGap(ComponentPlacement.RELATED)
        			.addGroup(gl_jPanel5.createParallelGroup(Alignment.LEADING)
        				.addComponent(jLabel6, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE)
        				.addComponent(jTextFieldB, GroupLayout.PREFERRED_SIZE, 131, GroupLayout.PREFERRED_SIZE))
        			.addGap(258))
        );
        gl_jPanel5.setVerticalGroup(
        	gl_jPanel5.createParallelGroup(Alignment.LEADING)
        		.addGroup(gl_jPanel5.createSequentialGroup()
        			.addGroup(gl_jPanel5.createParallelGroup(Alignment.BASELINE)
        				.addComponent(jLabel5)
        				.addComponent(jLabel6))
        			.addPreferredGap(ComponentPlacement.RELATED)
        			.addGroup(gl_jPanel5.createParallelGroup(Alignment.BASELINE)
        				.addComponent(jTextFieldA, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
        				.addComponent(jTextFieldB, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
        			.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel5.setLayout(gl_jPanel5);

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Апроксимація"));

        jComboBoxType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Лінійній СЕ", "Безсітковий+Штраф", "Безсітковий+Множники Лагранжа" }));
        jComboBoxType.setSelectedIndex(1);

        jLabel7.setText("n");

        jTextFieldN.setText("25");

        jLabel8.setText("Ядро");

        jComboBox4.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Гаусіан", "Кубічний сплайн", "Експонентційна", "Експонентційна_2" }));

        jLabel9.setText("Степінь");

        jTextFieldPow.setText("1");

        jLabel10.setText("Радіус");

        jTextFieldRho.setText("2.33");

        javax.swing.GroupLayout gl_jPanel6 = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(gl_jPanel6);
        gl_jPanel6.setHorizontalGroup(
            gl_jPanel6.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jComboBoxType, 0, 300, Short.MAX_VALUE)
            .addGroup(gl_jPanel6.createSequentialGroup()
                .addGroup(gl_jPanel6.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(gl_jPanel6.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jTextFieldN)
                    .addComponent(jComboBox4, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(gl_jPanel6.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(gl_jPanel6.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldPow, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE))
                    .addGroup(gl_jPanel6.createSequentialGroup()
                        .addComponent(jLabel10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jTextFieldRho, javax.swing.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE)))
                .addContainerGap())
        );
        gl_jPanel6.setVerticalGroup(
            gl_jPanel6.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gl_jPanel6.createSequentialGroup()
                .addComponent(jComboBoxType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(gl_jPanel6.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jTextFieldN, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(jTextFieldPow, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(gl_jPanel6.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(jComboBox4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addComponent(jTextFieldRho, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jButton1.setText("Розв'язати");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jTextFieldNorma.setText("jTextField1");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        layout.setHorizontalGroup(
        	layout.createParallelGroup(Alignment.LEADING)
        		.addGroup(layout.createSequentialGroup()
        			.addGroup(layout.createParallelGroup(Alignment.LEADING)
        				.addGroup(Alignment.TRAILING, layout.createSequentialGroup()
        					.addContainerGap()
        					.addComponent(jTextFieldNorma, GroupLayout.PREFERRED_SIZE, 127, GroupLayout.PREFERRED_SIZE)
        					.addPreferredGap(ComponentPlacement.RELATED, 51, Short.MAX_VALUE)
        					.addComponent(jButton1, GroupLayout.PREFERRED_SIZE, 104, GroupLayout.PREFERRED_SIZE))
        				.addComponent(jPanel6, 0, 0, Short.MAX_VALUE)
        				.addComponent(jPanel1, 0, 0, Short.MAX_VALUE)
        				.addComponent(jPanel2, 0, 0, Short.MAX_VALUE)
        				.addComponent(jPanel5, GroupLayout.PREFERRED_SIZE, 292, Short.MAX_VALUE))
        			.addContainerGap(159, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
        	layout.createParallelGroup(Alignment.LEADING)
        		.addGroup(layout.createSequentialGroup()
        			.addComponent(jPanel1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
        			.addPreferredGap(ComponentPlacement.RELATED)
        			.addComponent(jPanel2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
        			.addPreferredGap(ComponentPlacement.RELATED)
        			.addComponent(jPanel5, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
        			.addPreferredGap(ComponentPlacement.RELATED)
        			.addComponent(jPanel6, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
        			.addPreferredGap(ComponentPlacement.RELATED)
        			.addGroup(layout.createParallelGroup(Alignment.LEADING)
        				.addGroup(layout.createSequentialGroup()
        					.addComponent(jButton1, GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE)
        					.addContainerGap(55, Short.MAX_VALUE))
        				.addGroup(layout.createSequentialGroup()
        					.addComponent(jTextFieldNorma, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
        					.addContainerGap())))
        );
        this.setLayout(layout);
    }// </editor-fold>//GEN-END:initComponents

    private void jTextFieldQActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldQActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldQActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        int n = Integer.parseInt(this.jTextFieldN.getText());
        int Degree = Integer.parseInt(this.jTextFieldPow.getText());
        double a = Double.parseDouble(this.jTextFieldA.getText());
        double b = Double.parseDouble(this.jTextFieldB.getText());
        double left = Double.parseDouble(this.jTextFieldBLeft.getText());
        boolean DirihletA = true;
        if(this.jComboBoxA.getSelectedIndex()==1){
            DirihletA = false;
        }
        boolean DirihletB = true;
        if(this.jComboBoxB.getSelectedIndex()==1){
            DirihletB = false;
        }
        double right = Double.parseDouble(this.jTextFieldBRight.getText());
        String p = this.jTextFieldP.getText();
        String q = this.jTextFieldQ.getText();
        String w = this.jTextFieldW.getText();
        final String f = this.jTextFieldF.getText();



        if (this.jComboBoxType.getSelectedIndex()==0) {
            //вузли ...
            double h = (b-a)/(double)n;
            ArrayList<Double> list = new ArrayList<Double>();
            for (int i = 0; i <= n; i++) {
                list.add(a+h*i);
            }

            MainMatrixGenerator1 gen = new MainMatrixGenerator1(list);
            gen.setfString(f);
            gen.setwString(w);
            gen.setqString(q);
            gen.setpString(p);

            gen.setLeft(a);
            gen.setRight(b);
            gen.setAVal(left);
            gen.setBVal(right);
            gen.setDirihetA(DirihletA);
            gen.setDirihetB(DirihletB);
            long startTime = System.currentTimeMillis();
            gen.Generate();
            final double[] res = gen.Solve("");

            final ArrayList<FEMShapeFunction1D1> femlist = new ArrayList<FEMShapeFunction1D1>();

            for (int i = 0; i <= n; i++) {
                femlist.add(new FEMShapeFunction1D1(list.get(i), h));
            }

            GaussQuadrature gau = new GaussQuadrature(50);
            System.out.println(gau.Gauss(a, b, 0.000001, new IFunction1D() {

                public double calculate(double x) {
                    double tmp = 0.0;
                    for (int j = 0; j <femlist.size(); j++) {
                        tmp+= femlist.get(j).calculate(x)*res[j];
                    }
                    return tmp*tmp;
                }

                public double calculateDerivaty(double x) {
                    throw new UnsupportedOperationException("Not supported yet.");
                }
            }));
            
            System.out.println("Energy\t\t"+gau.Gauss(a, b, 0.000001, new IFunction1D() {

                public double calculate(double x) {
                    double tmp = 0.0;
                    for (int j = 0; j <femlist.size(); j++) {
                        tmp+= femlist.get(j).calculate(x)*res[j];
                    }
                    try {
						return tmp*PostfiksX.Calculate(f, x);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					return 0.0;
                }

                public double calculateDerivaty(double x) {
                    throw new UnsupportedOperationException("Not supported yet.");
                }
            }));

            XYSeries series1 = new XYSeries("розвязок лінійного МСЕ", true, true);
            for (int i = 0; i < res.length; i++) {
                series1.add((double)list.get(i),(double)res[i]);
                System.out.println(list.get(i)+"\t"+res[i]);
            }

            NewOkCancelDialog dialog = new NewOkCancelDialog(null, false, new XYSeriesCollection(series1));
            dialog.setLocationRelativeTo(this);
            //dialog.setUndecorated(true);
            dialog.setVisible(true);
        }
        if (this.jComboBoxType.getSelectedIndex()==1) {
            // Penalty
            
            double rho = Double.parseDouble(this.jTextFieldRho.getText());
            ArrayList<Particle> ls1D = new ArrayList<Particle>();
            final ArrayList<JMeshlessInterpolationFunction1D> MeshlessShapeList = new ArrayList<JMeshlessInterpolationFunction1D>();
            double h = (b-a)/(double)n;
            
            IKernelFunction kernal = null;
            switch(jComboBox4.getSelectedIndex()){
                case 0: kernal = new JGaussian(rho*h); break;
                case 1: kernal = new JCubicSpline(rho*h); break;
                case 2: kernal = new JExponential(0.7,rho*h); break;
                case 3: kernal = new JStKernel(rho*h); break;
                //case 4: kernal = new JSt2Kernel(); break;
                default: kernal = new JGaussian(rho*h);
            }
            
            for (int i = 0; i <=n; i++) {
                ls1D.add(new Particle(a+h*i, 0, i));
                ls1D.get(ls1D.size()-1).setRho(rho*h);
                MeshlessShapeList.add(new JMeshlessInterpolationFunction1D(Degree, a+i*h, rho*h, kernal));
            }

            MF1DSolver solver = new MF1DSolver();
            solver.setfString(f);
            //solver.setwString("-"+w);
            solver.setwString(w);
            solver.setqString(q);
            solver.setpString(p);
            solver.setAVal(left);
            solver.setBVal(right);
            solver.setDirihetA(DirihletA);
            solver.setDirihetB(DirihletB);
            solver.setRight(b);
            solver.setLeft(a);

            solver.setListOfShapeFunction(MeshlessShapeList);
            solver.setNodeList(ls1D);


            long startTime = System.currentTimeMillis();


            solver.generate();
            final double[] res = solver.solvePenalty();

            System.out.println((System.currentTimeMillis()-startTime));


            GaussQuadrature gau = new GaussQuadrature(50);
            double r = (gau.justGauss(a, b, new IFunction1D() {

                public double calculate(double x) {
                    double tmp = 0.0;
                    for (int j = 0; j <res.length; j++) {
                        tmp+= MeshlessShapeList.get(j).calculate(x)*res[j];
                    }
                    return tmp*tmp;
                }

                public double calculateDerivaty(double x) {
                    throw new UnsupportedOperationException("Not supported yet.");
                }
            }));
            
            System.out.println("Energy\t\t"+gau.justGauss(a, b, new IFunction1D() {

                public double calculate(double x) {
                    double tmp = 0.0;
                    for (int j = 0; j <MeshlessShapeList.size(); j++) {
                        tmp+= MeshlessShapeList.get(j).calculate(x)*res[j];
                    }
                    try {
						return tmp*PostfiksX.Calculate(f, x);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					return 0.0;
                }

                public double calculateDerivaty(double x) {
                    throw new UnsupportedOperationException("Not supported yet.");
                }
            }));
            

            System.out.println("L2\t\t"+r+"");
            this.jTextFieldNorma.setText(r+"");

            
            
            System.out.println("Total concentration\t\t"+gau.justGauss(a, b, new IFunction1D() {

                public double calculate(double x) {
                    double tmp = 0.0;
                    for (int j = 0; j <MeshlessShapeList.size(); j++) {
                        tmp+= MeshlessShapeList.get(j).calculate(x)*res[j];
                    }
                    try {
						return tmp;
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					return 0.0;
                }

                public double calculateDerivaty(double x) {
                    throw new UnsupportedOperationException("Not supported yet.");
                }
            }));
            
          //max sol
            double max = -1;
            double min = 100000;
            double maxX = 0;
            double minX = 0;
            for(double x=a;x<=b;x+=0.001){
            	double tmp = 0.0;
                for (int j = 0; j <MeshlessShapeList.size(); j++) {
                    tmp+= MeshlessShapeList.get(j).calculate(x)*res[j];
                }
                if (tmp>max) {
                	max = tmp;
                	maxX = x;
				}
                if (tmp<min) {
                	min = tmp;
                	minX = x;
				}
            }
            System.out.println("Max concentration in point \t\tx = "+maxX+"\t\t value = "+max);
            System.out.println("Min concentration in point \t\tx = "+minX+"\t\t value = "+min);
            
          //max velocity
             max = -1;
             min = 100000;
             maxX = 0;
             minX = 0;
            for(double x=a;x<=b;x+=0.001){
            	double tmp = 0.0;
                for (int j = 0; j <MeshlessShapeList.size(); j++) {
                    tmp+= MeshlessShapeList.get(j).calculateDiffuseDerivaty(x)*res[j];
                }
                if (tmp>max) {
                	max = tmp;
                	maxX = x;
				}
                if (tmp<min) {
                	min = tmp;
                	minX = x;
				}
            }
            System.out.println("Max velocity in point \t\tx = "+maxX+"\t\t value = "+max);
            System.out.println("Min velocity in point \t\tx = "+minX+"\t\t value = "+min);
            


            XYSeries series1 = new XYSeries("розвязок методом штрафу", true, true);
            double x = 0;
            while(x<=1.001){
                double tmp = 0.0;
                for (int j = 0; j <res.length; j++) {
                    tmp+= MeshlessShapeList.get(j).calculate(x)*res[j];
                }
                series1.add(x,tmp);
                System.out.println(x+"\t\t"+tmp);
                x+=0.001;
            }

            NewOkCancelDialog dialog = new NewOkCancelDialog(null, false, new XYSeriesCollection(series1));
            dialog.setLocationRelativeTo(this);
            //dialog.setUndecorated(true);
            dialog.setVisible(true);
        }

        if (this.jComboBoxType.getSelectedIndex()==2) {
            // Lagrange
            IKernelFunction kernal = null;
                
            double rho = Double.parseDouble(this.jTextFieldRho.getText());
            ArrayList<Particle> ls1D = new ArrayList<Particle>();
            final ArrayList<JMeshlessInterpolationFunction1D> MeshlessShapeList = new ArrayList<JMeshlessInterpolationFunction1D>();
            double h = (b-a)/(double)n;
            switch(jComboBox4.getSelectedIndex()){
                    case 0: kernal = new JGaussian(rho*h); break;
                    case 1: kernal = new JCubicSpline(rho*h); break;
                    case 2: kernal = new JExponential(0.7,rho*h); break;
                    case 3: kernal = new JStKernel(rho*h); break;
                    //case 4: kernal = new JSt2Kernel(); break;
                    default: kernal = new JGaussian(rho*h);
                }
            for (int i = 0; i <=n; i++) {
                ls1D.add(new Particle(a+h*i, 0, i));
                ls1D.get(ls1D.size()-1).setRho(rho*h);
//                MeshlessShapeList.add(new JMeshlessInterpolationFunction1D(Degree, a+i*h, rho*h, kernal));
                MeshlessShapeList.add(new JMeshlessInterpolationFunction1D(Degree, a+i*h, rho*h, new JGaussian(rho*h)));
            }



            MF1DSolver solver = new MF1DSolver();
            solver.setfString(f);
//            solver.setwString("-"+w);
            solver.setwString(w);
            solver.setqString(q);
            solver.setpString(p);
            
            solver.setRight(b);
            solver.setLeft(a);

            solver.setListOfShapeFunction(MeshlessShapeList);
            solver.setNodeList(ls1D);


            long startTime = System.currentTimeMillis();

            solver.generate();

            solver.setAVal(left);
            solver.setBVal(right);
            solver.setDirihetA(DirihletA);
            solver.setDirihetB(DirihletB);

            final double[] res = solver.solveLagrangeMulti();





                        System.out.println((System.currentTimeMillis()-startTime));


            GaussQuadrature gau = new GaussQuadrature(50);
            System.out.println("L2\t\t"+gau.Gauss(a, b, 0.000001, new IFunction1D() {

                public double calculate(double x) {
                    double tmp = 0.0;
                    for (int j = 0; j <MeshlessShapeList.size(); j++) {
                        tmp+= MeshlessShapeList.get(j).calculate(x)*res[j];
                    }
                    return tmp*tmp;
                }

                public double calculateDerivaty(double x) {
                    throw new UnsupportedOperationException("Not supported yet.");
                }
            }));

            System.out.println("Energy\t\t"+gau.Gauss(a, b, 0.000001, new IFunction1D() {

                public double calculate(double x) {
                    double tmp = 0.0;
                    for (int j = 0; j <MeshlessShapeList.size(); j++) {
                        tmp+= MeshlessShapeList.get(j).calculate(x)*res[j];
                    }
                    try {
						return tmp*PostfiksX.Calculate(f, x);
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					return 0.0;
                }

                public double calculateDerivaty(double x) {
                    throw new UnsupportedOperationException("Not supported yet.");
                }
            }));



        double x = 0;
        while(x<=1.0001){
            double tmp = 0.0;
            for (int j = 0; j <res.length-2; j++) {
                tmp+= MeshlessShapeList.get(j).calculate(x)*res[j];
            }
            System.out.print(x+"\t"+tmp+"\n");
            x+=0.01;
        }


            XYSeries series1 = new XYSeries("розвязок множниками Лагранжа", true, true);
            x = 0;
            while(x<=1.0001){
                double tmp = 0.0;
                for (int j = 0; j <MeshlessShapeList.size(); j++) {
                    tmp+= MeshlessShapeList.get(j).calculate(x)*res[j];
                }
                series1.add(x,tmp);
                x+=0.01;
            }

            NewOkCancelDialog dialog = new NewOkCancelDialog(null, false, new XYSeriesCollection(series1));
            dialog.setLocationRelativeTo(this);
            //dialog.setUndecorated(true);
            dialog.setVisible(true);
        }

    }//GEN-LAST:event_jButton1ActionPerformed

    private void jTextFieldWActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldWActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextFieldWActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JComboBox jComboBox4;
    private javax.swing.JComboBox jComboBoxA;
    private javax.swing.JComboBox jComboBoxB;
    private javax.swing.JComboBox jComboBoxType;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JTextField jTextFieldA;
    private javax.swing.JTextField jTextFieldB;
    private javax.swing.JTextField jTextFieldBLeft;
    private javax.swing.JTextField jTextFieldBRight;
    private javax.swing.JTextField jTextFieldF;
    private javax.swing.JTextField jTextFieldN;
    private javax.swing.JTextField jTextFieldNorma;
    private javax.swing.JTextField jTextFieldP;
    private javax.swing.JTextField jTextFieldPow;
    private javax.swing.JTextField jTextFieldQ;
    private javax.swing.JTextField jTextFieldRho;
    private javax.swing.JTextField jTextFieldW;
    // End of variables declaration//GEN-END:variables


    public static void main(String[] args){
        ParamsPanel p = new ParamsPanel();
        JFrame f = new JFrame("одновимірна задача");
        f.getContentPane().add(p);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setMinimumSize(new Dimension(322, 528));
        f.setResizable(false);
        f.setSize(322, 528);
        f.setLocationRelativeTo(null);
        f.setVisible(true);
    }

}
